﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class LevelHideReplayRotateHeart : MonoBehaviour
{
    public GameLevelItem gameLevelItem;
    public Button btn;
    public List<Transform> heartList = new List<Transform>();
    private int tempIndex = 0;
    // Start is called before the first frame update
    void Start()
    {
        btn.onClick.AddListener(() =>
        {
            SoundManager.Instance.PlayAudio(SoundType.Click.ToString(), false);
            btn.enabled = false;
            GameCtrl.Instance.playPanel.EnablePlayPanelBtn(false);
            Invoke("RotateHeart", 0.1f);
        });
    }

    private void RotateHeart()
    {
        heartList[tempIndex].DOLocalRotate(Vector3.zero, 0.1f);
        tempIndex++;
        if (tempIndex == heartList.Count)
        {
            Invoke("TriggerWin", 0.5f);
        }
        else
            Invoke("RotateHeart", 0.1f);
    }

    private void TriggerWin()
    {
        gameLevelItem.TriggerResult(true);
    }
}
